package com.zpz.framework.zpzoauth.common.oauth;

import com.zpz.framework.zpzoauth.common.redis.ZpzOauthRedisService;
import com.zpz.framework.zpzoauth.common.utils.ZpzOauthCommonConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
/**
 * @author zhangpanzhi
 * @time 2019-07-09
 * @description 未经本人允许请勿随便改动，尊重劳动
 * */
@Component
public class ZpzOauthTokenUtils {
    @Resource
    private ZpzOauthRedisService zpzOauthRedisService;
    public static String APPLICATION_NAME;
    @Value("${zpzOauth.redis.pre}")
    public void setApplicationName(String applicationName){
        APPLICATION_NAME=applicationName;
    }

    public  boolean logout(String ucode,String clientId){
        String access_token_key= APPLICATION_NAME+"_"+ ZpzOauthCommonConstant.CLIENT_INFO+":client_id:"+clientId+":user:"+ucode+":access_token";
        boolean access_token_delete = zpzOauthRedisService.delete(access_token_key);
        String refresh_token_key= APPLICATION_NAME+"_"+ ZpzOauthCommonConstant.CLIENT_INFO+":client_id:"+clientId+":user:"+ucode+":refresh_token";
        boolean refresh_token_delete = zpzOauthRedisService.delete(refresh_token_key);
        return access_token_delete&&refresh_token_delete;
    }
}
